package com.blb.thread;

import java.util.Random;

public class BaoziShopDemo {

    public static void main(String[] args) {
//        BaoziShop shop = new BaoziShop();
        BaoziShop2 shop = new BaoziShop2();
        Random random = new Random();
        //两个师傅分别做了50包子
        new Thread(() -> {
            for (int j = 0; j < 3; j++) {
                shop.makeBaozi();
                try {
                    Thread.sleep(random.nextInt(200));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        //10个消费者吃10个包子
        new Thread(() -> {
            for (int j = 0; j < 3; j++) {
                shop.sellBaozi();
                try {
                    Thread.sleep(random.nextInt(400));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
